﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CuitWinEdit.cs" company="">
//   
// </copyright>
// <summary>
//   The cuit win edit.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace UITest.CUIT.CuitControls.WinControls
{
    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UITesting.WinControls;

    /// <summary>
    ///     The cuit win edit.
    /// </summary>
    public class CuitWinEdit : CuitWinControl<WinEdit>
    {
        #region Constructors and Destructors

        /// <summary>
        ///     Initializes a new instance of the <see cref="CuitWinEdit" /> class.
        /// </summary>
        public CuitWinEdit()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinEdit"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        public CuitWinEdit(UITestControl testControl)
            : base(testControl)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinEdit"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        public CuitWinEdit(UITestControl testControl, string searchProperties)
            : base(testControl, searchProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinEdit"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        /// <param name="filterProperties">
        /// The filter properties.
        /// </param>
        public CuitWinEdit(UITestControl testControl, string searchProperties, string filterProperties)
            : base(testControl, searchProperties, filterProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinEdit"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        public CuitWinEdit(ICuitControlBase wrappedControl, string searchProperties)
            : base(wrappedControl, searchProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinEdit"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        /// <param name="filterProperties">
        /// The filter properties.
        /// </param>
        public CuitWinEdit(ICuitControlBase wrappedControl, string searchProperties, string filterProperties)
            : base(wrappedControl, searchProperties, filterProperties)
        {
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///     Gets or sets the copy pasted text.
        /// </summary>
        public string CopyPastedText
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.CopyPastedText;
            }

            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(value);
                this._control.CopyPastedText = value;
            }
        }

        /// <summary>
        ///     Gets the current line.
        /// </summary>
        public int CurrentLine
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.CurrentLine;
            }
        }

        /// <summary>
        ///     Gets or sets the insertion index absolute.
        /// </summary>
        public int InsertionIndexAbsolute
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.InsertionIndexAbsolute;
            }

            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(value.ToString());
                this._control.InsertionIndexAbsolute = value;
            }
        }

        /// <summary>
        ///     Gets the insertion index line relative.
        /// </summary>
        public int InsertionIndexLineRelative
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.InsertionIndexLineRelative;
            }
        }

        /// <summary>
        ///     Gets a value indicating whether is password.
        /// </summary>
        public bool IsPassword
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.IsPassword;
            }
        }

        /// <summary>
        ///     Gets the line count.
        /// </summary>
        public int LineCount
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.LineCount;
            }
        }

        /// <summary>
        ///     Gets the max length.
        /// </summary>
        public int MaxLength
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.MaxLength;
            }
        }

        /// <summary>
        ///     Sets the password.
        /// </summary>
        public string Password
        {
            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(value);
                this._control.Password = value;
            }
        }

        /// <summary>
        ///     Gets a value indicating whether read only.
        /// </summary>
        public bool ReadOnly
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.ReadOnly;
            }
        }

        /// <summary>
        ///     Gets or sets the selection end.
        /// </summary>
        public int SelectionEnd
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.SelectionEnd;
            }

            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(value.ToString());
                this._control.SelectionEnd = value;
            }
        }

        /// <summary>
        ///     Gets or sets the selection start.
        /// </summary>
        public int SelectionStart
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.SelectionStart;
            }

            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(value.ToString());
                this._control.SelectionStart = value;
            }
        }

        /// <summary>
        ///     Gets or sets the selection text.
        /// </summary>
        public string SelectionText
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.SelectionText;
            }

            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(value);
                this._control.SelectionText = value;
            }
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///     The get text.
        /// </summary>
        /// <returns>
        ///     The <see cref="string" />.
        /// </returns>
        public string GetText()
        {
            this._control.WaitForControlReady();
            return this._control.Text;
        }

        /// <summary>
        /// The set text.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        public void SetText(string text)
        {
            this._control.WaitForControlReady();
            this._control.Text = text;
            this.WriteTestOutput(text);
        }

        /// <summary>
        /// The typing.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        public void Typing(string text)
        {
            this._control.WaitForControlReady();
            this._control.SetFocus();
            Keyboard.SendKeys(text);
            this.WriteTestOutput(text);
        }

        #endregion
    }
}